<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="referrer" content="no-referrer" />
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body,
        html {
            height: 100%;
            background-color: #ddd;
        }

        li {
            list-style-type: none;
        }

        .container {
            width: 1000px;
            margin: 0 auto;
        }

        .container ul {
            width: 1100px;
        }

        .container ul::after {
            content: "";
            clear: both;
            display: block;
        }

        .container ul li {
            float: left;
            height: auto;
            margin: 0 20px 20px 0;
            border-top: 0 none;
            background-color: #fff;
            border-radius: 2px;
            width: 235px;
        }

        .container ul li img {
            width: 100%;
        }

        .container ul li p {
            width: 100%;
            line-height: 40px;
            padding-left: 10px;
        }
    </style>
</head>

<body>
    <!-- 瀑布流容器 -->
    <div class="container">
        <!-- 瀑布流定位容器 -->
        <ul class="wrapper">
            <!-- 每个瀑布流元素 -->
            <!-- <li>
                <img src="https://c-ssl.duitang.com/uploads/item/202004/21/20200421222241_TvCXF.thumb.400_0.jpeg"
                    alt="">
                <p>粘土手作希小怪</p>
            </li>
            <li>
                <img src="https://c-ssl.duitang.com/uploads/item/202004/21/20200421222241_TvCXF.thumb.400_0.jpeg"
                    alt="">
                <p>粘土手作希小怪</p>
            </li>
            <li>
                <img src="https://c-ssl.duitang.com/uploads/item/202004/21/20200421222241_TvCXF.thumb.400_0.jpeg"
                    alt="">
                <p>粘土手作希小怪</p>
            </li>
            <li>
                <img src="https://c-ssl.duitang.com/uploads/item/202004/21/20200421222241_TvCXF.thumb.400_0.jpeg"
                    alt="">
                <p>粘土手作希小怪</p>
            </li> -->
        </ul>

    </div>


    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
    <script src="./jquery.waterfall.js"></script>
    <script>
        $(function () {
            $.ajax({
                url: '/dt',
                data: {
                    include_fields: 'top_comments,is_root,source_link,item,buyable,root_id,status,like_count,sender,album,reply_count', filter_id: '手工DIY',
                    start: 24,
                    _: Date.now()
                }
            })
                .then(function (res) {

                    show(res.data.object_list);
                    $(".wrapper li").waterFall({
                        col: 4
                    });
                })

            function show(data) {
                var htmlStr = '';
                for (let i = 0; i < data.length; i++) {
                    var n_w = 235;
                    // 图片实际的宽度;
                    var w = data[i].photo.width;
                    // 图片的实际高度;
                    var h = data[i].photo.height;
                    // 当前图片的高度;
                    var n_h = n_w / w * h;
                    htmlStr += `<li>
                                <img src="${data[i].photo.path}" height=${parseInt(n_h)}>
                                <p>${data[i].msg}</p>
                            </li>`;
                }
                $('.wrapper').html(htmlStr);
            }
        })

    </script>
</body>

</html>